package com.blueocean_health.care.management.transfer.client;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.blueocean_health.care.management.domain.base.SysResult;
import com.blueocean_health.care.management.domain.dto.NurseWorkerInfoRequestDto;
import com.blueocean_health.care.management.domain.dto.RequestIdDto;
import com.blueocean_health.care.management.transfer.client.NurseWorkerService.HystrixClientFallback;

@FeignClient(value = "workerserver", fallback = HystrixClientFallback.class)
public interface NurseWorkerService {

	/**
	 * 获取护工详情
	 */
	@RequestMapping(value = "nurse/query", consumes="application/json; charset=utf-8")
	public SysResult findDetail(RequestIdDto requestId);

	/**
	 * 获取护工列表分页
	 */
	@RequestMapping(value = "nurse/list", consumes="application/json; charset=utf-8")
	public SysResult findList(NurseWorkerInfoRequestDto nurseWorkerInfoRequestDto);

	/**
	 * 导出护工Execl
	 */
	@RequestMapping(value = "nurse/listNurseWorkerInfoExcel", consumes="application/json; charset=utf-8")
	public SysResult listNurseWorkerInfoExcel(NurseWorkerInfoRequestDto nurseWorkerInfoRequestDto);

	@Component
	static class HystrixClientFallback implements NurseWorkerService {
		private static Logger logger = LoggerFactory.getLogger(HystrixClientFallback.class);

		private SysResult getResult(Object object) {

			if (object instanceof String) {
				logger.info("异常发生，进入fallback方法，接收的参数：" + String.valueOf(object));
				return SysResult.error(String.valueOf(object));
			} else {
				logger.info("异常发生，进入fallback方法，接收的参数：" + JSON.toJSONString(object));
				return SysResult.error(JSON.toJSONString(object));
			}
		}

		@Override
		public SysResult findDetail(RequestIdDto requestId) {
			return getResult(requestId);
		}

		@Override
		public SysResult findList(NurseWorkerInfoRequestDto nurseWorkerInfoRequestDto) {
			return getResult(nurseWorkerInfoRequestDto);
		}

		@Override
		public SysResult listNurseWorkerInfoExcel(NurseWorkerInfoRequestDto nurseWorkerInfoRequestDto) {
			return getResult(nurseWorkerInfoRequestDto);
		}

	}
}
